package com.sunday.volunteer.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

import com.sunday.volunteer.R;
import com.sunday.volunteer.entity.Member;
import com.sunday.volunteer.entity.Order;
import com.sunday.volunteer.entity.Product;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2017/1/10.
 */

public class OrderAdapter extends RecyclerViewAdapter{

    public OrderAdapter(List list, int layout) {
        super(list, layout);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(View itemView, int viewType) {
        return new ViewHolder(itemView);
    }
    public class ViewHolder extends MyViewHolder{
        @Bind(R.id.order_type)
        TextView order_type;
        @Bind(R.id.name)
        TextView name;
        @Bind(R.id.desc)
        TextView desc;
        @Bind(R.id.price)
        TextView price;
        @Bind(R.id.num)
        TextView num;
        @Bind(R.id.image_view)
        ImageView image_view;
        @Bind(R.id.order_no)
        TextView order_no;
        @Bind(R.id.order_score)
        TextView order_score;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this , itemView);
            itemView.setOnClickListener(onClickListener);
        }

        @Override
        public void bind(MyViewHolder holder, Object object, int position) {
            Order item = (Order)object;
            itemView.setTag(R.id.item ,item);
            if(item == null){
                return;
            }

            setText(order_no , String.format("订单号%s" ,item.getOrderNo()));
            setText(order_score , String.format("合计%.0f%s" ,item.getTotalAmount(), "积分" ) );
            setText(order_type , item.getOrderStatusStr());

            if(item.getProducts() != null && item.getProducts().get(0) != null){
                Product product = item.getProducts().get(0);
                setText(name , product.getName());
                //setText(desc , product.getName());
                setText(price , String.format("%.0f%s" ,product.getPrice() ,"积分") );
                setText(num , String.format("数量：%d" ,product.getNumber()));
                setImage(image_view ,product.getImage() , 120 ,120);
            }

        }
    }
}
